package controller

import (
	"github.com/kataras/iris/v12"
	"log"
	"palms/model"
	"palms/service"
	"strconv"
)

type RobotController struct {
	Service service.RobotService
}

func (c *RobotController) Get(ctx iris.Context) []model.Robot {
	pn := ctx.URLParam("pageNo")
	ps := ctx.URLParam("pageSize")
	var pageNo = 1
	var pageSize = 20
	var err error
	if ps != "" {
		pageNo, err = strconv.Atoi(pn)
		if err != nil {
			log.Println("pageNo参数错误[" + pn + "]")
		}
	}
	if ps != "" {
		pageSize, err = strconv.Atoi(ps)
		if err != nil {
			log.Println("pageSize参数错误[" + ps + "]")
		}
	}
	return c.Service.List(pageNo, pageSize)
}

func (c *RobotController) GetBy(id int64) model.Robot {
	return c.Service.Get(id)
}

func (c *RobotController) Delete(id int64) interface{} {
	c.Service.Delete(id)
	return iris.StatusBadRequest
}
